//
//  TIMFriendInfoCell.m
//  Demo_sdk
//
//  Created by Deli Xia on 2018/7/7.
//  Copyright © 2018年 Deli Xia. All rights reserved.
//

#import "TIMFriendInfoCell.h"
#import "Masonry.h"
#import "TIMDemoMacro.h"
#import "UIView+Extension.h"

@implementation TIMFriendInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configUI];
    }
    return self;
}

- (void)configUI{
    
    self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
    self.selectedBackgroundView.backgroundColor = RGBColor(238, 238, 238);
    [self.contentView addSubview:self.titleLab];
    [_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.width.mas_equalTo(80);
        make.top.mas_equalTo(16);
    }];
    [self.contentView addSubview:self.detaileLab];
    [_detaileLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.width.mas_equalTo(Screen_Width - 100);
        make.top.mas_equalTo(16);
    }];
}

- (UILabel *)titleLab
{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = TPSFontSize(14);
        _titleLab.textColor = RGBColor(51, 51, 51);
    }
    return _titleLab;
}

- (UILabel *)detaileLab
{
    if (!_detaileLab) {
        _detaileLab = [[UILabel alloc] init];
        _detaileLab.font = TPSFontSize(14);
        _detaileLab.numberOfLines = 0;
        _detaileLab.textAlignment = NSTextAlignmentRight;
        _detaileLab.textColor = RGBColor(117, 117, 117);
    }
    return _detaileLab;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}
@end

@implementation TIMFriendOperationCell
- (void)configUI {
    [super configUI];
    self.operationSwitch = [[UISwitch alloc] init];
    self.operationSwitch.onTintColor = UIColor.blueColor;
    
    //状态需要储存到数据库。
    //    self.operationSwitch.on = NO;
    [self.operationSwitch addTarget:self action:@selector(operationAction:) forControlEvents:UIControlEventValueChanged];
    [self.contentView addSubview:self.operationSwitch];
    
    [self.operationSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(51, 31));
        make.trailing.mas_offset(-12);
        make.centerY.mas_equalTo(self.titleLab.centerY);
    }];
}

- (void)operationAction:(UISwitch *)sender {
    if (self.operationBlock) {
        self.operationBlock(self.operationSwitch.isOn);
    }
}
@end
